use std::env;
use std::fmt::write;
use std::fs;
use std::io::{self, Write};
use std::process;
use std::process::exit;

fn main() -> io::Result<()>{
    let args: Vec<String> = env::args().collect();
    
    if args.len() != 2{
        eprintln!("[-] Usage {} <path to shellcode.bin>", args[0]);
        exit(0);
    }

    let path = &args[1];
    let bytes = fs::read(path)?;

    let len = bytes.len();

    println!("const SHELLCODE: [u8; {}] = [", len);

    let stdout = io::stdout();
    let mut handle = stdout.lock();

    for (i, &byte) in bytes.iter().enumerate() {
        if i % 16 == 0 && i != 0{
            writeln!(handle)?;
            write!(handle, "    ")?;
        } else if i != 0{
            write!(handle, " ")?;
        }
        write!(handle, "0x{:02X},", byte)?;
    }
    
    writeln!(handle)?;
    writeln!(handle, "];")?;

    
    Ok(())
}